<%@ page language="java" import="java.util.*,java.sql.*"
	pageEncoding="UTF-8"%>
<html>
<head>
<title>修改信息</title>
</head>

<body>
	<%
		try {
			Class.forName("com.mysql.jdbc.Driver");
			String url1 = "jdbc:mysql://localhost:3306/user";
			String url2 = "?user=root&password=123456";
			String url3 = "&useUnicode=true&characterEncoding=UTF-8";
			String url = url1 + url2 + url3;
			Connection con = DriverManager.getConnection(url);
			request.setCharacterEncoding("UTF-8");
			String user = (String)session.getAttribute("user");
			String name1 = request.getParameter("name1");
			int id = Integer.parseInt(request.getParameter("id"));
			String name = request.getParameter("name");
			String num = request.getParameter("num");
			String sql = "update person set id=?, name=?, num=? where name=? and user="+"'"+user+"'";
			PreparedStatement pstmt = con.prepareStatement(sql);
			pstmt.setInt(1, id);
			pstmt.setString(2, name);
			pstmt.setString(3, num);
			pstmt.setString(4, name1);
			int n = pstmt.executeUpdate();
			if (n >= 1)
				out.print("修改成功" + "<br>");
			else
				out.print("修改失败" + "<br>");
			if (pstmt != null) {
				pstmt.close();
			}
			if (con != null) {
				con.close();
			}

		} catch (Exception e) {
			e.printStackTrace();
		}
	%>
	<h3>请输入修改人姓名</h3>
	<form action="change.jsp" method="post">
		<h3 style="text-align: center;">修改信息</h3>
		<table style="margin: auto;">
			<tr>
				<td>name</td>
				<td><input type="text" name="name1"></td>
			</tr>
		</table>
		<h3>请输入要修改的信息</h3>
		<table style="margin: auto;">
			<tr>
				<td>ID</td>
				<td><input type="text" name="id"></td>
			</tr>
			<tr>
				<td>姓名</td>
				<td><input type="text" name="name"></td>
			</tr>
			<tr>
				<td>电话</td>
				<td><input type="text" name="num"></td>
			</tr>
			<tr>
				<td><input type="submit" value="提交">
				</td>
				<td><input type="reset" value="取消">
				</td>
			</tr>
		</table>
	</form>
</body>
</html>
